# coding: utf-8
from PySide6.QtWidgets import QFileDialog
from qfluentwidgets import GroupHeaderCardWidget, TransparentPushButton, ComboBox, FluentIcon, CheckBox, PrimaryPushButton, PushButton

from common import SingleIcon


class BasicSettingCard(GroupHeaderCardWidget):
    def _postInit(self):
        super()._postInit()
        # 入口文件
        self.entryFileBtn = PushButton(SingleIcon.Python, self.tr("选择Python文件"), self)
        self.entryFileCard = self.addGroup(SingleIcon.Python, self.tr("入口文件"), self.tr("请选择入口文件"),
                                           self.entryFileBtn)
        # 软件的打包类型
        self.packTypeComboBox = ComboBox(self)
        self.packTypeCard = self.addGroup(SingleIcon.Joystick, self.tr("软件的打包类型"),
                                          self.tr("请选择软件的打包类型"),
                                          self.packTypeComboBox)
        # 是否显示命令行终端
        self.showTerminalCheckBox = CheckBox(self.tr("显示命令行终端"),self)
        self.showTerminalCard = self.addGroup(FluentIcon.COMMAND_PROMPT, self.tr("是否显示命令行终端"),
                                              self.tr("勾选此项可在软件运行时显示命令行终端"),
                                              self.showTerminalCheckBox)
        # 选择软件的图标
        self.iconBtn = PushButton(FluentIcon.DOCUMENT, self.tr("选择软件的图标"), self)
        self.iconCard = self.addGroup(FluentIcon.PHOTO, self.tr("选择软件的图标"), self.tr("请选择软件的图标"),
                                      self.iconBtn)
        # 开始打包
        self.startBtn = PrimaryPushButton(FluentIcon.PLAY,self.tr("开始打包"), self)
        self.startCard = self.addGroup(FluentIcon.PLAY_SOLID, self.tr("打包"), self.tr("点击此项开始打包软件"),
                                       self.startBtn)

        self.__initWidgets()

    def __initWidgets(self):
        self.setTitle(self.tr("基本设置"))

        self.packTypeComboBox.addItem(self.tr("单文件"), "single")
        self.packTypeComboBox.addItem(self.tr("文件夹"), "folder")

        self.__connectSignals()

    def __connectSignals(self):
        self.entryFileBtn.clicked.connect(self.__selectEntryFile)
        self.iconBtn.clicked.connect(self.__selectIcon)

    def __selectEntryFile(self):
        filePath, _ = QFileDialog.getOpenFileName(self, self.tr("选择入口文件"), "",
                                                  self.tr("Python 文件 (*.py *.pyw)"))
        if filePath:
            self.entryFileCard.setContent(filePath)

    def __selectIcon(self):
        iconPath, _ = QFileDialog.getOpenFileName(self, self.tr("选择软件的图标"), "",
                                                  self.tr("图标文件 (*.ico *.png *.jpg)"))
        if iconPath:
            self.iconCard.setContent(iconPath)


class PyinstallerSettingCard(BasicSettingCard):
    pass


class NuitkaSettingCard(BasicSettingCard):
    pass
